package leetCode.hw.string;

import java.util.ArrayList;
import java.util.List;

public class HJ20Solution implements HJ20{

    @Override
    public List<String> verifyPasswords(List<String> passwords) {
        List<String> result = new ArrayList<>();
        for(String password:passwords) {
            result.add(verify(password));
        }
        return result;
    }

    public static String verify(String password) {
        String result = "OK";
        if(password.length()<=8) result = "NG";
        int num = 0;
        if(password.matches(".*[a-z].*")) num++;
        if(password.matches(".*[A-Z].*")) num++;
        if(password.matches(".*[0-9].*")) num++;
        if(password.matches(".*[^a-zA-Z0-9\\n\\s].*")) num++;
        if(num<3) result = "NG";
        for(int i=0;i<password.length()-3;i++){
            String s = password.substring(0,i)+password.substring(i+3);
            if(s.contains(password.substring(i,i+3))){
                result = "NG";
                break;
            }

        }
        return result;
    }
}
